﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static CommonMethod.MyConfigSection;

namespace CommonMethod
{
    public static class ReadConfig
    {
        /// <summary>
        /// 读取配置文件自定义节点
        /// </summary>
        public static Dictionary<string, MyKeyValueCollection> Email { get; }
        static ReadConfig()
        {
            ExeConfigurationFileMap map = new ExeConfigurationFileMap();
            map.ExeConfigFilename = System.Web.Hosting.HostingEnvironment.MapPath("/") + "User.config";
            Configuration userConfig = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
            ConfigurationSectionGroup EmailGroup = userConfig.GetSectionGroup("ExpireEmail");
            Email = new Dictionary<string, MyKeyValueCollection>();
            foreach (MyConfigSection item in EmailGroup.Sections)
            {

                Email.Add(item.SectionInformation.Name, item.KeyValues);
            }

        }

    }
}
